import shutil

import cv2
import os
import scipy.io as sio

r''' 
1、提取E:\uav_datasets\Drone-Detection-RTB\[cls_name]\clips目录下的所有视频clips，放到同名的cls_name目录下
2、共4个类别
'''

cls_nms = {'AIRPLANE',
           'BIRD',
           'DRONE',
           'HELICOPTER'}

root_path = r'E:\uav_datasets\Drone-Detection-RTB'
target_path = r'E:\uav_datasets\Drone-Detection-RTB-UAV4'

vid_dirs = os.listdir(root_path)  # ['V_AIRPLANE_012', 'V_BIRD_003', ... ]
total = 0
for vid_dir in vid_dirs:
    if vid_dir.startswith("MUTI_"): continue  # 跳过存在多目标的视频
    src_clips_path = os.path.join(root_path, vid_dir, 'clips')  # 拼接源路径
    print('当前处理：', str(src_clips_path))
    dst_clips_path = ''  # 复制的目标路径
    for cls_nm in cls_nms:
        if vid_dir.find(cls_nm) != -1:
            dst_clips_path = os.path.join(target_path, cls_nm)
            if not os.path.exists(dst_clips_path):
                os.mkdir(dst_clips_path)
            break
    if not dst_clips_path:
        print("未知的视频clips类别：", vid_dir)
    print(src_clips_path, ' to ', dst_clips_path)
    src_clips = os.listdir(src_clips_path)
    for clip in src_clips:
        shutil.copyfile(os.path.join(src_clips_path, clip),
                        os.path.join(dst_clips_path, clip))
